import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:multi_image_picker_view/multi_image_picker_view.dart';
import 'package:qianyi/entity/home/ImageVideoDetailEntity.dart';
import 'package:qianyi/entity/home/tag_vo_list_entity.dart';

import '../entity/message/Message.dart';

class HomeTabController extends GetxController {
  Message? messageItem;
  String? tagDetailId;
  String albumDetailId = '';

  // 创建响应式变量来保存最新和最热的数据
  final RxList<String> tabs = <String>['热门', '其它'].obs;
  String searchName = '';
  final RxInt currentIndex = 0.obs;
  late TabController tabController;
  RxInt showIndex = 0.obs;
  RxBool addImage = false.obs;
  RxList<TagVo> selectTags = <TagVo>[].obs;
  RxList<TagVo> tagVos = RxList<TagVo>();
  RxBool isPubshing = false.obs;

  RxList<ImageFile> videoFiles = RxList<ImageFile>();
  RxSet<ImageFile> imageFiles = RxSet<ImageFile>();
  //把发布的部分信息都写在这个对象里了
  final selectFQ = RxMap<String, String>();
  MultiImagePickerController? imageController = null;
  String setAddAlbumImageId = '';
  RxBool isNoTag = true.obs;
  // 初始化TabController
  void setTabController(TickerProvider vsync) {
    tabController = TabController(
      initialIndex: currentIndex.value,
      length: tabs.length,
      vsync: vsync,
    );

    // 监听TabController的索引变化
    tabController.addListener(() {
      currentIndex.value = tabController.index;
    });

    // 监听currentIndex的变化来更新TabController的索引
    ever(currentIndex, (index) {
      if (tabController.index != index) {
        tabController.animateTo(index);
      }
    });
  }

  void setSelectTags(TagVo s) {
    if(this.selectTags.length == 5 || s.name!.length > 20) return;
    this.selectTags.add(s);
  }

  void removeTag(TagVo tag) {
    this.selectTags.remove(tag);



  }

  void setEditTags(ImageVideoDetailEntity first) {
    this.selectTags.clear();
    for(int i =0; i < first.tagList!.length; i++) {
      TagList tagList = first.tagList![i];
      TagVo tagVo = TagVo();
      tagVo.name = tagList.name;
      tagVo.count = tagList.count;
      this.selectTags.value.add(tagVo);
    }
    return ;
  }
  void setCategory(ImageVideoDetailEntity first) {
    this.selectFQ["oneId"] = first.categoryPid!;
    this.selectFQ['twoId'] = first.categoryId!;
    this.selectFQ["oneValue"] = first.categoryPName!;
    String twoVale = first.categoryName!;
    this.selectFQ["twoValue"] = twoVale;
    print("haha");
  }
// 可以添加其他方法来更新数据等
}
